package geektime.concurrent.part2.executors;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecutorDemo {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor threadPoolExecutor =
            new ThreadPoolExecutor(3, 10, 100,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(5));
        for (int i = 0; i < 10; i++) {
            threadPoolExecutor.execute(() -> {
                System.out.println(Thread.currentThread().getName() + " is working");
                try {
                    TimeUnit.SECONDS.sleep(100);
                } catch (InterruptedException e) { e.printStackTrace(); }
            });
        }
        System.out.println("corePoolSize: " + threadPoolExecutor.getCorePoolSize());
        System.out.println("poolSize: " + threadPoolExecutor.getPoolSize());
    }
}
